<include file="Public/head"/>
<body class="no-skin">
<include file="Public/header"/>
<div class="main-container" id="main-container">
    <script type="text/javascript">
        try {
            ace.settings.check('main-container', 'fixed')
        } catch (e) {
        }
    </script>

    <include file="Public/sidebar"/>
    <div class="main-content">
        <div class="main-content-inner">
            <!-- #section:basics/content.breadcrumbs -->
            <include file="Public/breadcrumbs"/>

            <!-- /section:basics/content.breadcrumbs -->
            <div class="page-content">
                <include file="Public/set"/>

                <!-- /section:settings.box -->
                <div class="row">
                    <div class="col-xs-12">
                        <form class="form-horizontal" id="form" method="post" action="{:U('updateactivity')}">
                            <input type="hidden" name="id" id="id"  value="{$activity['id']}">
                            <!-- PAGE CONTENT BEGINS -->
                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" for="form-field-0">活动类型</label>
                                <div class="col-sm-9">
                                    <select id="type" name="type" class="col-xs-10 col-sm-5">
                                        <option value="1" <if condition="$activity['type'] eq 1">selected</if>>--限时免费--</option>
                                        <!--<option value="0" <if condition="$activity['type'] eq 0">selected</if>>&#45;&#45;其他&#45;&#45;</option>-->
                                        </foreach>
                                    </select>

                                    <span class="help-inline col-xs-12 col-sm-7">
												<span class="middle">选择所属分类。</span>
											</span>
                                </div>
                            </div>

                            
                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" for="form-field-0">活动状态</label>
                                <div class="col-sm-9">
                                    <select id="status" name="status" class="col-xs-10 col-sm-5">
                                        <option value="1" <if condition="$activity['status'] eq 1">selected</if>>--开启--</option>
	                                    <option value="0" <if condition="$activity['status'] eq 0">selected</if>>--关闭--</option>
	                                    </foreach>
                                    </select>

                                    <span class="help-inline col-xs-12 col-sm-7">
												<span class="middle">选择所属分类。</span>
											</span>
                                </div>
                            </div>



                            


                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" for="form-field-0">活动描述</label>
                                <div class="col-sm-9">
                                    <input type="text" name="description" id="description" placeholder="活动描述"
                                           class="col-xs-10 col-sm-5" value="{$activity['description']}">


                                </div>
                            </div>



                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" for="form-field-0">活动时间</label>
                                <div class="col-sm-9">
                                    <font color="green">开始时间:</font><input name="start_time" type="text"  onClick="WdatePicker()" readonly="readonly"
                                                                           value="{$activity['start_time']}">
                                    <font color="green">结束时间:</font><input name="end_time" type="text"  onClick="WdatePicker()" readonly="readonly"
                                                                            value="{$activity['end_time']}">

                                </div>
                            </div>

							<div class="form-group" >
                                <label class="col-sm-1 control-label no-padding-right" for="form-field-0">添加小说</label>
                                <div class="col-sm-9" id="dianji">
                                    <input type="text" name="" id="novel_name" placeholder="请填写小说名称"
                                           class="col-xs-10 col-sm-5 textbox" value="请填写小说名称" disabled>

                                    <a class="help-inline col-xs-12 col-sm-7">
                                        <div style="height:34px "><a id="add">点击添加</a><br/></div>
											</span>
                                </div>
                            </div>

                            <!--王溪加的-->
                            <table class="table table-striped table-bordered">
                                <thead>
                                <tr>

                                    <th class="center">参加活动的小说</th>
                                    <th class="center">操作</th>

                                </tr>
                                </thead>
                                <tbody>
                                <volist name="novel_name" id="val">
                                    <tr class="shanchuhang">
                                        <td class="center"><input  class="shanchuzhi" disabled type="text" name="novel_name[]" value="{$val['name']}"></td>
                                        <td class="center" ><a class="shanchu">点击删除</a></td>
                                    </tr>
                                </volist>
                                </tbody>
                            </table>

                                <!--结束-->






                            <!--<div class="space-4"></div>
                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" for="form-field-4">
                                    活动海报 </label>
                                <div class="col-sm-9">
                                    <div class="col-xs-10 col-sm-5">
                                        {:UpImage("img",100,100,$novel['img'])}
                                    </div>
                                    <span class="help-inline col-xs-12 col-sm-7">
												<span class="middle">仅支持jpg、gif、png、bmp、jpeg，且小于1MB。</span>
											</span>
                                </div>

                            </div>-->
                            <div class="space-4"></div>

                            <div class="col-md-offset-2 col-md-9">
                                <button class="btn btn-info submit" type="button">
                                    <i class="icon-ok bigger-110"></i>
                                    提交
                                </button>

                                &nbsp; &nbsp; &nbsp;
                                <button class="btn" type="reset">
                                    <i class="icon-undo bigger-110"></i>
                                    重置
                                </button>
                            </div>

                            <!-- PAGE CONTENT ENDS -->


                        </form>
                    </div><!-- /.col -->
                </div><!-- /.row -->
            </div><!-- /.page-content -->
        </div>
    </div><!-- /.main-content -->
    <include file="Public/footer"/>

</div><!-- /.main-container -->

<include file="Public/footerjs"/>
<!-- inline scripts related to this page -->
<script type="text/javascript">
    $(function () {
        /**
         * 点击添加小说名字
         */
        /**
         * 点击添加小说名字
         */
        $('#add').click(function(){
            //添加节点
            $('#dianji').append('<div class="textbox">' +
                '<input type="text" name="novel_name[]">' +
                '<a class="deletes">&nbsp&nbsp&nbsp&nbsp点击删除</a>' +
                '</div>');
            $('.deletes').on("click",function(){
                $(this).parent().remove();
            });


//
            $('.textbox').find('input').on('blur',function () {
                $.ajax({
                    url:'{:U("findnovel")}',
                    data:{
                        novel_name:$(this).val(),
                    },
                    type:'POST',
                    datatype:'json',
                    success:function(data){
                        //将data字符串转换成对象
                        var dataobj = JSON.parse(data);
                        if(dataobj.status == 201){
                            layer.msg(dataobj.msg, {icon: 2});
                        }else{

                        }

                    }
                })
            });



        });

        //点击删除小说
        $('.shanchu').on('click',function(){
            //alert($(this).parent().prev().find('.shanchuzhi').val());
            $(this).parent().parent().remove();
            $.ajax({
                url:'{:U('ajaxnovel')}',
                data:{
                    novel_name:$(this).parent().prev().find('.shanchuzhi').val(),
                },
                type:'POST',
                datatype:'json',

            });
        });




        $("#tabs").tabs();
        var editor = KindEditor.create('textarea[name="content"]', {
            uploadJson: '__PUBLIC__/kindeditor/php/upload_json.php',
            fileManagerJson: '__PUBLIC__/kindeditor/php/file_manager_json.php',
            allowFileManager: true,
            afterBlur: function () {
                this.sync();
            }
        });
        $(".submit").click(function () {
            var classid = $("#class_id").val();
            var otherclassid = $("#other_class_id").val();
            var title = $("#title").val();
            var content = $("#content").val();
            var description = $("#description").val();
            if (classid == 0) {
                bootbox.dialog({
                    title: '友情提示：',
                    message: "小说分类必须选择。",
                    buttons: {
                        "success": {
                            "label": "确定",
                            "className": "btn-danger"
                        }
                    }
                });
                return;
            }
            if (otherclassid == 0) {
                bootbox.dialog({
                    title: '友情提示：',
                    message: "小说特别分类必须选择。",
                    buttons: {
                        "success": {
                            "label": "确定",
                            "className": "btn-danger"
                        }
                    }
                });
                return;
            }            
            if (novel_name == '') {
                bootbox.dialog({
                    title: '友情提示：',
                    message: "小说名字至少填写一个填写。",
                    buttons: {
                        "success": {
                            "label": "确定",
                            "className": "btn-danger"
                        }
                    }
                });
                return;
            }
            /*if (description == '') {
                bootbox.dialog({
                    title: '友情提示：',
                    message: "小说摘要必须填写。",
                    buttons: {
                        "success": {
                            "label": "确定",
                            "className": "btn-danger"
                        }
                    }
                });
                return;
            } */
            $("#form").submit();
        });
        
        $("#class_id").change(function(){
        	var class_name = $("#class_id").find("option:selected").text();
        	class_name = class_name.replace(/-/g,"");
        	$("#class_name").val(class_name);
        });
        
        $("#other_class_id").change(function(){
        	var class_name = $("#other_class_id").find("option:selected").text();
        	class_name = class_name.replace(/-/g,"");
        	$("#other_class_name").val(class_name);
        });        
    });
</script>
</body>
</html>
